#pragma once

#define TGN_BYTE	unsigned char
#define TGN_DWORD	unsigned long
#define TGN_WORD	unsigned short

#define MAX_FRAMES 50
#define MAX_ANIS   50


struct TGNFrame
{
	int x, y, w, h;
	int delay;
	int hotx, hoty;
	int boundx, boundy;
};

struct TGNAni
{
	char name[10];

	TGN_BYTE ID;
	TGN_BYTE nextID;

	TGN_BYTE numFrames;
	TGNFrame frames[MAX_FRAMES];

	int boundW, boundH;
};

struct TGNHeader
{
	char ver;
	TGN_BYTE ID;
	TGN_BYTE numFrames;
	TGN_BYTE numAnis;
	int alpha;

	TGN_BYTE numLetters;
	char *imageName;
};

class TGNFile
{
private:
	TGNHeader header;
	TGNAni anis[MAX_ANIS];

	bool loaded;

public:
	TGNFile();

	int Load(char *filename);
	int Save(char *filename);
	int Unload();

	TGN_BYTE GetAniCount() { return header.numAnis; }

	int SetImageName(char *filename);
	char *GetImageName();

	int AddFrame(TGN_BYTE AniIndex, TGNFrame *newFrame);
	int SetFrame(TGN_BYTE AniIndex, TGN_BYTE FrmIndex, int x, int y, int w, int h, int delay);
	int DeleteFrame(TGN_BYTE AniIndex, TGN_BYTE FrameIndex);
	TGNFrame *GetFrame(TGN_BYTE AniIndex, TGN_BYTE FrameIndex);
	int SetHotspot(TGN_BYTE AniIndex, TGN_BYTE FrameIndex, int hx, int hy);
	int SetBounds(TGN_BYTE AniIndex, TGN_BYTE FrameIndex, int bx, int by);
	int NumAnis() { return header.numAnis; }

	int AddAni(TGNAni *newAni);
	int DeleteAni(TGN_BYTE index);
	TGNAni *GetAni(TGN_BYTE index);
	int SetAni(TGN_BYTE index, TGN_BYTE ID, TGN_BYTE nextID, int boundw, int boundh, char *name);
	int DeleteAllAnis();

	int SetAlpha(int newAlpha);
	int SetID(int newID);
	TGN_BYTE GetID();

	void Clear();

};
